package registnet.base;

import java.util.List;
import java.util.ListIterator;
import java.util.Vector;

import registnet.base.source.ChecklistSource;
import registnet.dao.Student;
import registnet.dao.StudentPeer;

/**
 * A class that handles processes which involves a set of checklists.
 */
public class ChecklistPeer implements IChecklistPeer {

	/**
	 * The list of checklists.
	 */
	private List<IChecklist> checklists;
	
	/**
	 * Default constructor.
	 */
	public ChecklistPeer(){
		checklists = new Vector<IChecklist>();
		load();
	}
	
	/**
	 * Computes the demand for a course in the next enlistment process. 
	 * 
	 * @param courseCode
	 * @return the demand for the course with the given course code.
	 */
	public int getDemandPrediction(String courseCode) {
		int demand = 0;
		ListIterator<IChecklist> li = checklists.listIterator();
		while(li.hasNext()){
			IChecklist checklist = li.next();
			if(checklist.isRecommended(courseCode))
				demand++;
		}
		return demand;
	}
	
	@Override
	public void load(){
		ListIterator<Student> li = new StudentPeer().getAllStudents().listIterator();
		while(li.hasNext()){
			Student student = li.next();
			IChecklist checklist = new ChecklistSource(student.getStudentNumber()).getChecklist();
			addChecklist(checklist);
		}
	}
	
	@Override
	public void addChecklist(IChecklist checklist) {
		checklists.add(checklist);
	}

}
